#!/usr/bin/env python
# *-* encoding: utf8
# 
# Copyright (c) 2006 Stian Soiland
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Author: Stian Soiland <stian@soiland.no>
# URL: http://soiland.no/i/src/
# License: MIT
#
"""Common XML namespaces.

Namespace objects for usage with ElementTree.
"""


class NS(object):
    NS = ""
    tags = ""
    class __metaclass__(type):
        def __new__(cls, name, bases, dict):
            if not ("tags" in dict and "NS" in dict):
                raise "Cannot create NS class without defining tags and NS"
            ns = dict["NS"]
            for tag in dict["tags"].split():
                dict[tag] = "{%s}%s" % (ns, tag)
            return type.__new__(cls, name, bases, dict)


class DAV(NS):
    NS = "DAV:"
    tags = """multistatus response href propstat prop
              resourcetype creationdate getlastmodified
              getetag supportedlock lockentry lockscope locktype
              lockdiscovery getcontenttype getcontentlength
              status collection shared exclusive write"""

class ApacheProps(NS):
    NS = "http://apache.org/dav/props/"
    tags = "executable"

